<?php
/**
 * 
 * 更新用户教育信息
 * @author yangchao
 * @since 2012-03-19
 */
if (!file_exists("../SINASRV_CONFIG")) {
	echo "Read the sinasrv config error!\n";
//	exit();
} else {
   $array_config = parse_ini_file("../SINASRV_CONFIG", true); var_dump($array_config);
   
   $_SERVER = array_merge($_SERVER, $array_config); 
}


/*ini_set("display_errors",ture);
error_reporting(E_ALL);*/

define("CRON_NAME","update_user_mblog_count");//cro名称，要求唯一
set_time_limit(0);
$_GET["db_debug"] = true;
$_GET["no_pref_debug"] = true;

include_once($_SERVER['DOCUMENT_ROOT'] ."/include/user/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/tucao/inc.php");
include_once($_SERVER['DOCUMENT_ROOT'] ."/include/mblog/inc.php");

class mod_cron_engine_main extends mod_cron_engine
{
	function __construct($current_process_id)
	{
		parent::__construct($current_process_id,CRON_NAME);
	}
	
	
	function craw()
	{
		$this->get_data();
	}
	
	
	function  run()
	{
		//开始跑cron之前预先获取数据（start_id等）
		$this->before_run();
		
		//正式获取数据
		$this->craw();
		
		
		$this->after_run();
	}
	
	
	function get_data()
	{
		$sql = "select count(*) as count from user_info where count_tuijian > 0";
		
		$db_base = new db_base();
		$count = $db_base->select($sql);
		$count = $count[0]["count"];
		echo "tag_count:$count<br>\n";
		$total_page = ceil($count/PCOUNT);
		
		for($i=1;$i<=$total_page;$i++)
		{
			$this->get_list_by_page($i);
		}
		
		
	}	
	
	function get_list_by_page($p)
	{
		$start = ($p-1)*PCOUNT;
		
		$sql = "select uid from user_info where count_tuijian > 0 limit  0," .PCOUNT;
		
		$db_base = new db_base();
		$list = $db_base->select($sql);
		
		$uid_array = array();
		foreach($list as $value)
		{
			$uid = $value["uid"];
			$sql = "select counr(*) as count from mblog_pic_content where create_uid = '{$uid}'";
			$res = $db_base->select($sql);
			$count = $res[0]["count"];
			$sql = "update user_info set count_tuijian =  $count,count_mblog = $count where uid = '{$uid}'";
			$res = $db_base->query($sql);
		}
		
		
	}
	
	
	
	
}

$m = new mod_cron_engine_main(NOW_PROCESS);
$m->run();
